window.onload = function () {
    const app = Vue.createApp({
        data(){
            return {

            }
        },
        methods:{
            logout(){
                const xhr = new XMLHttpRequest();
                xhr.open("GET", "http://localhost:8080/LogOutServlet");
                xhr.send();
                window.location.href="login.html";
            },
            updateUserInfo(){
                window.location.href="updateUserInfo.html";
            },
            purchaseBook(){
                window.location.href="shoppingCart.html";
            }
        },
        created:function (){
            const xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:8080/LogInServlet");
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        if(xhr.response !== 'true'){
                            window.location.href="login.html";
                        }
                    }
                }
            }
        }
    }).mount("#app");
}